package com.zhang.wanx.service.impl;

import com.zhang.wanx.common.model.GenerationResDTO;
import com.zhang.wanx.common.util.WangXiangRpc;
import com.zhang.wanx.service.IHuaWeiYunService;
import com.zhang.wanx.service.IWanXiangService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-03-26 17:33
 **/
@RequiredArgsConstructor
@Slf4j
@Service
public class WanXiangService implements IWanXiangService {

    private final WangXiangRpc wangXiangRpc;
    private final IHuaWeiYunService huaWeiYunService;

    @Override
    public String generation(MultipartFile file, Integer styleIndex) {

        String imageUrl = huaWeiYunService.fileUpload(file);
        if(Objects.isNull(imageUrl)){
            log.error("未能上传成功");
            return null;
        }

        GenerationResDTO generation = wangXiangRpc.generation(imageUrl, styleIndex);

        return generation.getOutput().getTask_id();
    }

    @Override
    public GenerationResDTO tasks(String id) {

        return wangXiangRpc.tasks(id);
    }
}
